﻿using System;
using System.Windows;
using System.Windows.Controls;
using GameLogic.Controls;
using GameLogic.Logic;

namespace TestUi.Content
{
    public partial class SingleCollisionGame : UserControl, IGameFeatures
    {
        GameLoop gameLoop;
        
        // IGameFeatures event handlers
        public event EventHandler<ScoresChangedEventArgs> ScoresChanged;
        public event EventHandler<LivesChangedEventArgs> LivesChanged;
        public event EventHandler<TimeChangedEventArgs> TimeChanged;
        //public event EventHandler<HighscoreEntryArgs> HighscoreEntryFired;
        //public event EventHandler PauseTimerFired;
        //public event EventHandler ResumeTimerFired;
        public event EventHandler GameOver;
        //public event EventHandler NewGameFired;

        public SingleCollisionGame()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(OnLoaded);
        }

        void OnLoaded(object sender, RoutedEventArgs e)
        {
            // Find the GameLoop
            GameLoopFinder glf = new GameLoopFinder(LayoutRoot);
            gameLoop = glf.GameLoop;
        }

        #region IGameFeatures Methods
        public void Start()
        {
            if (gameLoop != null)
                gameLoop.StartGameLoop();
        }

        public void Stop()
        {
            if (gameLoop != null)
                gameLoop.ResetGameLoop();
        }

        public void Pause()
        {
            if (gameLoop != null)
                gameLoop.PauseGameLoop();
        }

        public void Resume()
        {
            if (gameLoop != null)
                gameLoop.StartGameLoop();
        }

        public void ChangeScores(int inc)
        {

        }

        public void ChangeLives(int inc)
        {

        }

        #endregion


        public bool IsTimeBased
        {
            get { return true; }
        }

        public bool IsLifeBased
        {
            get { return true; }
        }

        public string GameName
        {
            get { return "Test UI"; }
        }


        public TimeSpan GameDuration
        {
            get { throw new NotImplementedException(); }
        }


        event EventHandler<GameOverEventArgs> IGameFeatures.GameOver
        {
            add { throw new NotImplementedException(); }
            remove { throw new NotImplementedException(); }
        }

        public string DeveloperName
        {
            get { throw new NotImplementedException(); }
        }

        public string CompanyName
        {
            get { throw new NotImplementedException(); }
        }

        public string Description
        {
            get { throw new NotImplementedException(); }
        }

        public Uri SettingsPage
        {
            get { return null; }
        }


        public void OnScoresChanged(int scores)
        {
        }

        public void OnLivesChanged(int lives)
        {
        }
    }
}
